//
//  KZWithdrawRecordVC.swift
//  BoyeStore
//
//  Created by 朱凯 on 2018/6/28.
//  Copyright © 2018年 itboye. All rights reserved.
//

import UIKit

class KZWithdrawRecordVC: KZBaseViewControllerWithBack {

    let table = UITableView()
    var emptyView: KZMessageEmptyView! = nil
    
    var items: [String] = [] {
        didSet {
            table.reloadData()
            
            if items.count == 0 {
                table.backgroundView = emptyView
            } else {
                table.backgroundView = UIView()
            }
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        navigationItem.title = "提现记录"
        view.backgroundColor = kBgColor
        setupUI()
    }
    
    override func viewSafeAreaInsetsDidChange() {
        if #available(iOS 11.0, *) {
            table.snp.makeConstraints { (m) in
                m.bottom.equalTo(view.safeAreaInsets.bottom)
            }
        }
    }

   
}
extension KZWithdrawRecordVC {
    
    func setupUI() {
        
        table.layer.cornerRadius = 8
        table.layer.masksToBounds = true
        table.backgroundColor = UIColor.white
        table.estimatedRowHeight = 200
        table.rowHeight = UITableViewAutomaticDimension
        table.separatorStyle = .none
        table.tableFooterView = UIView()
        table.delegate = self
        table.dataSource = self
        
        table.register(KZWithdrawRecordCell.self, forCellReuseIdentifier: "cell")
        
        view.addSubview(table)
        table.snp.makeConstraints { (m) in
            m.left.top.equalTo(10)
            m.right.bottom.equalTo(-10)
        }
        
        emptyView = KZMessageEmptyView(frame: table.bounds, image: #imageLiteral(resourceName: "消息-空"), text: "当前没有提现记录")

        items = ["", ""]
//        _ = delay(deadline: 3, execute: {
//            self.items = []
//        })
    }
}


// MARK: ------ tableview datasource
extension KZWithdrawRecordVC: UITableViewDelegate, UITableViewDataSource {
    
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return items.count
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell: KZWithdrawRecordCell = tableView.dequeueReusableCell(withIdentifier: "cell") as! KZWithdrawRecordCell
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        
        return 0
    }
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        
        return UIView()
    }
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0
    }
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        return UIView()
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
    }
}
